﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using thinger.MTHDAL;
using thinger.MTHModels;

namespace thinger.MTHDLL
{
    public class SysLogManage
    {
        private SysLogServer sysLogServer = new SysLogServer();

        public List<SysLog> SysLogByTime(string start, string end, string AlarmType)
        {
            try
            {
                List<SysLog> sysLogs = new List<SysLog>();
                DataTable dataTable = sysLogServer.SysLogByTime(start, end, AlarmType);
                for (int i = 0; i < dataTable.Rows.Count; i++)
                {
                    SysLog sysLog = new SysLog()
                    {
                        InsertTime = dataTable.Rows[i]["InsertTime"].ToString().Trim(),
                        Note = dataTable.Rows[i]["Note"].ToString().Trim(),
                        AlarmType = dataTable.Rows[i]["AlarmType"].ToString().Trim(),
                        Operator = dataTable.Rows[i]["Operator"].ToString().Trim(),
                        VarName = dataTable.Rows[i]["VarName"].ToString().Trim()
                    };

                    sysLogs.Add(sysLog);
                }
                return sysLogs;
            }
            catch (Exception)
            {

                return null;
            }
            
        }
        public List<SysLog> SysLogAll()
        {
            try
            {
                List<SysLog> sysLogs = new List<SysLog>();
                DataTable dataTable = sysLogServer.SysLogAll();
                for (int i = 0; i < dataTable.Rows.Count; i++)
                {
                    SysLog sysLog = new SysLog()
                    {
                        InsertTime = dataTable.Rows[i]["InsertTime"].ToString().Trim(),
                        Note = dataTable.Rows[i]["Note"].ToString().Trim(),
                        AlarmType = dataTable.Rows[i]["AlarmType"].ToString().Trim(),
                        Operator = dataTable.Rows[i]["Operator"].ToString().Trim(),
                        VarName = dataTable.Rows[i]["VarName"].ToString().Trim()
                    };

                    sysLogs.Add(sysLog);
                }
                return sysLogs;
            }
            catch (Exception)
            {

                return null;
            }
            
        }

        public int addSysLog(SysLog sysLog)
        {
            try
            {
                return sysLogServer.addSysLog(sysLog);
            }
            catch (Exception)
            {

                return -1;
            }
            
        }
    }
}
